home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NETWORK.SWG / 0012_WHOBE For NETWARE.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-21  |  3KB  |  94 lines

  1. {
  2. From: JIM ROBB
  3. Subj: Re: Netware "User name"
  4.  
  5.   I need a way to get the current user name from the netware shell.
  6.   For instance, if I'm logged into server MYSERVER as user SUPERVISOR,
  7.   I need some way to get 'supervisor' as the user name...
  8.  
  9. This should do the job.  The two calls are "Get Connection Number" (DCh) and
  10. "Get Connection Information" (E3h 16h), both from the Connection Services API.
  11. The calls work with Advanced Netware 1.0 and all later versions.  Code tested
  12. on 3.11 NetWare.
  13.  
  14. Beware the weak error-checking - the program doesn't check the version of
  15. Netware, or even that the user is logged onto the network.
  16. }
  17.  
  18. program WhoBeMe;
  19.  
  20. uses Dos;
  21.  
  22.  
  23. procedure GetUserName( var UserName : string );
  24.  
  25. var
  26.   Request : record                     { Request buffer for "Get Conn Info" }
  27.     Len  : Word;                       { Buffer length - 2                  }
  28.     Func : Byte;                       { Subfunction number ( = $16 )       }
  29.     Conn : Byte                        { Connection number to be researched }
  30.   end;
  31.  
  32.   Reply    : record                    { Reply buffer for "Get Conn Info"   }
  33.     Len    : Word;                     { Buffer length - 2                  }
  34.     ID     : Longint;                  { Object ID (hi-lo order)            }
  35.     Obj    : Word;                     { Object type (hi-lo order again)    }
  36.     Name   : array[ 1..48 ] of Byte;   { Object name as ASCII string        }
  37.     Time   : array[ 1.. 7 ] of Byte;   { Y, M, D, Hr, Min, Sec, DOW         }
  38.                                        { Y < 80 is in the next century      }
  39.                                        { DOW = 0 -> 6, Sunday -> Saturday   }
  40.     Filler : Byte                      { Call screws up without this!       }
  41.   end;
  42.  
  43.   Regs   : Registers;
  44.   W      : Word;
  45.  
  46. begin
  47.   Regs.AX := $DC00;                    { "Get Connection Number"            }
  48.   MsDos( Regs );
  49.                                        { "Get Connection Information"       }
  50.  
  51.   with Request do                      { Initialize request buffer:         }
  52.   begin
  53.     Len := 2;                                    { Buffer length,           }
  54.     Func := $16;                                 { API function,            }
  55.     Conn := Regs.AL                    { Returned in previous call!         }
  56.   end;
  57.  
  58.   Reply.Len := SizeOf( Reply ) - 2;    { Initialize reply buffer length     }
  59.  
  60.   with Regs do
  61.   begin
  62.     AH := $E3;                         { Connection Services API call       }
  63.     DS := Seg( Request );              { Location of request buffer         }
  64.     SI := Ofs( Request );
  65.     ES := Seg( Reply );                { Location of reply buffer           }
  66.     DI := Ofs( Reply );
  67.     MsDos( Regs )
  68.   end;
  69.  
  70.   if ( Regs.AL = 0 )                        { Success code returned in AL   }
  71.        and ( Hi( Reply.Obj ) = 1 )          { Obj of 1 is a user,           }
  72.        and ( Lo( Reply.Obj ) = 0 ) then     {   stored Hi-Lo                }
  73.     with Reply do
  74.     begin
  75.       Move( Name, UserName[ 1 ], 48 );           { Convert ASCIIZ to string }
  76.       UserName[ 0 ] := #48;
  77.       W := 1;
  78.       while ( UserName[ W ] <> #0 )
  79.             and ( W < 48 ) do
  80.         Inc( W );
  81.       UserName[ 0 ] := Char( W - 1 )
  82.     end
  83.   else
  84.     UserName := ''
  85. end;
  86.  
  87. var
  88.   TheName : string;
  89.  
  90. begin
  91.   GetUserName( TheName );
  92.   WriteLn( 'I be ', TheName )
  93. end.
  94.